package com.cms.plugins.plugins_market.controllers;

import com.cms.common.aop.permission.PermissionCheck;
import com.cms.common.model.vo.RequestData;
import com.cms.common.model.vo.ResponseResult;
import com.cms.controllers.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/admin/markets")
public class MarketController extends BaseController {
    @GetMapping("")
    @PermissionCheck(name = "我的插件", typeName = "开发者管理")
    public String index(Model viewModel) {
        return "market/index";
    }

    @GetMapping("/list")
    @ResponseBody
    @PermissionCheck(name = "我的插件列表", typeName = "开发者管理")
    public ResponseResult articles(@ModelAttribute RequestData requestData) {
        return ResponseResult.success(null);
    }

    @GetMapping("/create")
    @PermissionCheck(name = "创建插件界面", typeName = "开发者管理")
    public String create(Model viewModel) {
        return "market/form";
    }

    @GetMapping("/upload/plugin")
    @PermissionCheck(name = "上传插件", typeName = "开发者管理")
    public String uploadPlugin(Model viewModel) {
        //TODO 上传压缩包，解压，把相关配置信息显示到界面
        return "market/form";
    }

    @GetMapping("/upload/logo")
    @PermissionCheck(name = "上传插件Logo", typeName = "开发者管理")
    public String uploadLogo(Model viewModel) {
        return "market/form";
    }


    @PostMapping("/store")
    @PermissionCheck(name = "创建插件", typeName = "开发者管理")
    @ResponseBody
    public ResponseResult store(@RequestParam("name") String name,
                                @RequestParam("description") String description,
                                @RequestParam("price") double price,
                                @RequestParam("originalPrice") double originalPrice) {
        return ResponseResult.success("插件创建成功");
    }

    @GetMapping("/edit/{id}")
    @PermissionCheck(name = "修改插件界面", typeName = "开发者管理")
    public String edit(@PathVariable Long id, Model viewModel) {
        return "market/form";
    }

    @PutMapping("/update/{id}")
    @PermissionCheck(name = "修改插件", typeName = "开发者管理")
    @ResponseBody
    public ResponseResult update(@PathVariable Long id,
                                 @RequestParam("name") String name,
                                 @RequestParam("description") String description,
                                 @RequestParam("price") double price,
                                 @RequestParam("originalPrice") double originalPrice) {
        return ResponseResult.success("插件更新成功");
    }

    @DeleteMapping("/destroy/{id}")
    @PermissionCheck(name = "删除插件", typeName = "开发者管理")
    @ResponseBody
    public ResponseResult destroy(@PathVariable Long id) {
        return ResponseResult.success("插件删除成功");
    }
}
